"""
-*- coding:utf-8 -*-
__project__ = "python_study_one"
__file_name__ = "study2020_11_17"
__author__ = "admin"
__time__ = "2020/11/17 21:01"
__product_name__ = PyCharm 
"""
'''
学生管理系统 V1.0
1.添加学生
2.删除学生
3.修改学生
4.查询学生
5.显示所有学生
6.退出系统
'''
import sys

def menu_bar():  # 菜单栏
    print('学生管理系统 V1.0\n'
          '1.添加学生\n'
          '2.删除学生\n'
          '3.修改学生\n'
          '4.查询学生\n'
          '5.显示所有学生\n'
          '6.退出系统')

menu_bar()


global students_list   # 学生信息列表  所有学生信息 列表
global info_num        # 遍历列表后 学生各项信息  字典

students_list = []  # 列表，储存所有学生信息

def add_students():  # 1添加学生信息

    add_name = input("请输入姓名：")
    add_num = int(input("请输入学号(1-100之间的整数)："))
    add_tel = int(input("请输入电话："))
    # for info_num in students_list:
    #     if add_num == info_num['学号']:
    #         print("此学号已存在，请重新输入：")
    #         add_num = int(input("请输入学号(1-100之间的整数)："))
    #     else:
    #         return


    students_dict = {}  # 字典，储存学生信息

    students_dict["姓名"] = add_name
    students_dict["学号"] = add_num
    students_dict["电话"] = add_tel

    students_list.append(students_dict)
    print(students_list)
    choose_menu()


# global students_dict   # 添加的学生信息 字典
def del_students(): # 2通过学号删除学生
    global del_sure
    del_num = int(input("请输入要删除学生的学号："))
    for info_num in students_list:  # info_num遍历students_list列表
        if del_num == info_num['学号']:

            del_sure = input("请输入yes 或 no，‘yes’确认删除，‘no’取消删除")
            if del_sure == 'yes':
                students_list.remove(info_num)  # 删除列表中与输入学号相符的字典信息

                print('删除成功\n',students_list)

            else:
                print("取消删除")
                return

    choose_menu()


#
def change_students():  # 3修改学生信息

    change_num = int(input("请输入要修改学生的学号："))
    for info_num in students_list:  # info_num遍历students_list列表
        # print(info_num)
        if change_num == info_num['学号']:
            change_name = input("请输入要修改的姓名")
            info_num['姓名'] = change_name
            change_tel = int(input("请输入要修改的电话"))
            info_num['电话'] = change_tel
            print(students_list)

    # change_students()
    choose_menu()
#
#
def look_students():   # 4通过学号查看学生信息

    look_num = int(input("请输入要查询学生的学号："))
    for info_num in students_list:
        if look_num == info_num['学号']:
            print('当前学生信息为：',info_num)
        else:
            print("输入有误，请重新输入")
            look_students()
    choose_menu()


def look_all_students():   # 5查看所有学生信息

    # i = 0
    # for info in students_list:   # info去遍历students_list列表的学生信息 info是字典
    #     print("姓名：", info['姓名'], "学号：", info['学号'],"电话：", info['电话'])
    #     i += 1
    print('所有学生信息:',students_list)
    choose_menu()



#
#
#
def exit_system():   # 6退出系统
    user = input("你确定要退出系统吗？'yes'或'no'")
    if user == 'yes':
        print("已退出")
        sys.exit()
    elif user == 'no':
        choose_menu()
    else:
        print("输入有误，请重新输入：")
        exit_system()





def choose_menu():  # 菜单栏

    choose = int(input("请选择操作，输入对应序号即可"))
    if choose == 1:
        add_students()
    elif choose == 2:
        del_students()
    elif choose == 3:
        change_students()
    elif choose == 4:
        look_students()
    elif choose == 5:
        look_all_students()
    elif choose == 6:
        exit_system()
    else:
        print("输入有误，请重新输入")

choose_menu()